package cn.hqc.basic.controller;


import cn.hqc.basic.dto.SmsCodeDto;
import cn.hqc.basic.service.VerifyCodeService;
import cn.hqc.basic.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private VerifyCodeService verifyCodeService;

    /**
     * 获取图形验证码
     */
    @GetMapping("/image/{imageCodeKey}")
    public AjaxResult imageCode(@PathVariable("imageCodeKey") String imageCodeKey) throws IOException {
        String base64ImageCode = verifyCodeService.imageCode(imageCodeKey);
        return AjaxResult.success(base64ImageCode);
    }

    /**
     * 获取图形验证码
     */
    @PostMapping("/smsCode")
    public AjaxResult smsCode(@RequestBody @Valid SmsCodeDto dto) {
        verifyCodeService.smsCode(dto);
        return AjaxResult.success();
    }
}
